package com.oa.config.springSecurity;

import com.oa.entity.vo.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("mser")
public class MySecurityExpressRoot {
    public  boolean hasAuthority(String authority){
        //获取当前用户的权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        List<String> permissions = loginUser.getPermissions();
        for (String str:permissions) {
            System.out.println(str);
        }
        //判断用户权限是否在aurhority中
        return permissions.contains(authority);
    }
}
